<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentProfileSettings.class.php, $Author:  $ */

/** User settings
 *
 * Parameters:
 *  1. oUser (mandatory) - user account object
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentProfileSettings.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentProfileSettings extends BaseComponent
{

    /** Processing method
     */
	function process()
	{
	    $oAcc = $this->getParam('oUser');
	    /* @var $oAcc PhpFox_Mod_Account_ItemAccount */
	    $oCustomFieldService = &$this->_oModule->getService('CustomField');
	    /* @var $oCustomFieldService PhpFox_Mod_Account_ServiceCustomField */
	    assert($oAcc != null);

	    $oReq = &App::getRequest();
	    /* @var $oReq Request */
	    $aFields = $oCustomFieldService->getFieldsForProfile();
	    $aTextFields = $oCustomFieldService->getFieldsForProfileText();

	    // processing
        switch($oReq->getAction())
        {
            case 'update':
				$aFields = $oReq->getArray('field_option');
				$aFieldsText = $oReq->getArray('text_option');

				$oAcc->setData($oReq->getArray('aUser'));
				$oAcc->aData['p_update'] = time();

				$aUpdFields = array('headline', 'p_update');

				if (! $oAcc->update($aUpdFields))
			    {
			        $this->addErrors($oAcc->getErrors());
			    }

			    if (! $oCustomFieldService->updateProfileSettings($aFields, $aFieldsText))
			    {
			        $this->addErrors($oCustomFieldService->getErrors());
			    }

			    if (! $this->getErrors())
			    {
			        $oUrl = &App::getUrl();
			        App::forward($oUrl->getUrl(),
			                     array(App::format('Mod_Account.profile.updated')),
								 'message', App::getPageName(), 'ProfileSettings');
			    }
				break;
        }

		$oTpl = &$this->_oModule->getTemplate();
		$oTpl->assignSrc(array(
		    'aUser'         => $oAcc->aData,
		    'aFields'       => $aFields,
		    'aTextFields' => $aTextFields,
			'bIsHtml'       => App::getSetting('allow_html'),
			'aErrors'       => $this->getErrors(),
		));
		$srcHtml = $oTpl->fetch('ProfileSettings.html');
		return $srcHtml;
	}

}
?>